package com.kingdee.eas.hr.emp.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.eas.basedata.hraux.RegpermresidenceInfo;
import com.kingdee.eas.basedata.master.util.StringUtil;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.hr.emp.PersonContactMethodInfo;
import com.kingdee.eas.util.app.DbUtil;

public class PersonContactMethodControllerBeanEx extends PersonContactMethodControllerBean {

	@Override
	protected IObjectPK _addnew(Context ctx, IObjectValue model) throws BOSException, EASBizException {
		IObjectPK pk = super._addnew(ctx, model);
		PersonContactMethodInfo personContactMethodInfo = (PersonContactMethodInfo) model;

		StringBuffer buffer = new StringBuffer();
		buffer.append("UPDATE T_BD_PERSON SET ");
		if (StringUtil.isEmpty(personContactMethodInfo.getHjAddress())) {
			buffer.append("CFHJADDRESS=null,");
		} else {
			buffer.append("CFHJADDRESS='" + personContactMethodInfo.getHjAddress() + "',");
		}

		if (personContactMethodInfo.getRegresidence() != null) {
			RegpermresidenceInfo regpermresidenceInfo = personContactMethodInfo.getRegresidence();
			buffer.append("CFREGPERMRESIDENCE='" + regpermresidenceInfo.getId() + "' ");
		} else {
			buffer.append("CFREGPERMRESIDENCE=null ");
		}

		buffer.append("WHERE FID='" + personContactMethodInfo.getPerson().getId() + "'");

		DbUtil.execute(ctx, buffer.toString());
		return pk;
	}

	@Override
	protected void _update(Context ctx, IObjectPK pk, IObjectValue model) throws BOSException, EASBizException {
		super._update(ctx, pk, model);
		PersonContactMethodInfo personContactMethodInfo = (PersonContactMethodInfo) model;

		StringBuffer buffer = new StringBuffer();
		buffer.append("UPDATE T_BD_PERSON SET ");
		if (StringUtil.isEmpty(personContactMethodInfo.getHjAddress())) {
			buffer.append("CFHJADDRESS=null,");
		} else {
			buffer.append("CFHJADDRESS='" + personContactMethodInfo.getHjAddress() + "',");
		}

		if (personContactMethodInfo.getRegresidence() != null) {
			RegpermresidenceInfo regpermresidenceInfo = personContactMethodInfo.getRegresidence();
			buffer.append("CFREGPERMRESIDENCE='" + regpermresidenceInfo.getId() + "' ");
		} else {
			buffer.append("CFREGPERMRESIDENCE=null ");
		}

		buffer.append("WHERE FID='" + personContactMethodInfo.getPerson().getId() + "'");

		DbUtil.execute(ctx, buffer.toString());
	}
}
